package com.etbsms.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.etbsms.dao.IReportProblemDAO;
import com.etbsms.domain.ReportProblem;
import com.etbsms.util.Constants;

@Repository
@Component("reportProblemDAO")
public class ReportProblemDAOImpl extends GenericDAOImpl<ReportProblem, Integer> implements IReportProblemDAO{
	
	@Autowired
	public SessionFactory sessionFactory;


	@Override
	@SuppressWarnings("unchecked")
	public List<ReportProblem> getAll(Constants.REPORT_TYPE type) {		
		Session session = sessionFactory.openSession();
		Criteria criteria = session.createCriteria(ReportProblem.class);		
		if(type == Constants.REPORT_TYPE.notyet)
			criteria.add(Restrictions.eq("state",Constants.REPORT_STATE_NOTYET));
		else if(type == Constants.REPORT_TYPE.done)
			criteria.add(Restrictions.eq("state",Constants.REPORT_STATE_DONE));
		List<ReportProblem> list = criteria.list();
		session.close();
		
		
		return list;
	}	
}
